 <?php
//find.php
// This File outputs the filtered results out of the Input parameters
// Inputs :
// fn : File name
// q  : Filter String
// fl : File location
// sc : Select color (e.g. 'red','blue') 
// un : Unselect Color 
// d  : delimiter (this is the char that seperates each input at the file )
//rfs : Read from Session (default:1 , read values from Session) , use 0 value
//      for this paramter if reading is not enabled or not required (file content is dynamic not static) 


error_reporting(0);
session_start();
header("Cache-control: private"); //IE 6 Fix 

// fetch params from URL

$fileName = $_GET["fn"];
$what = $_GET["q"];
$fileLocation = $_GET["fl"];
$selectColor = $_GET["sc"];
$UnSelectColor = $_GET["usc"];
$delimiter = $_GET["d"];
$ReadFromSession = $_GET["rfs"];


// Read Values from Session if session params exists and configuration allows
if (isset($_SESSION['contentArray']) && ($ReadFromSession==1)) {
// reading Info from Session:
 $contentsArr = $_SESSION['contentArray'];
  }
else 
{
//Set defaults
if ($fileLocation=="default") $fileLocation="./";
if ($delimiter == "default") $delimiter=  "\n";

$fullPath = $fileLocation.$fileName;
$contents=file_get_contents($fullPath);
$contentsArr = array_unique(explode($delimiter, $contents));
$_SESSION['contentArray']=$contentsArr;
}

// Print each filterd result as a SPAN Object
foreach ($contentsArr as $line) {
   if (strpos($line,$what) === 0) $results[] = $line; }
   
   if (count($results[0]) > 0) {
	  foreach ($results as $key=>$result) {
	  echo '<SPAN id="sel" style="visibility:block"  onmouseover="Javascript:top.setit(this.innerHTML);
	         this.style.background=\''.$selectColor.'\'" onmouseout="this.style.background=\''.$UnSelectColor.'\'">'.$result.
			'</SPAN><br>';
			 }
   }
   
exit();							 

?>



